//package com.leyou.pojo.dto;
//
//import com.leyou.common.dto.BaseDTO;
//import com.leyou.common.entity.BaseEntity;
//import lombok.AllArgsConstructor;
//import lombok.Data;
//import lombok.EqualsAndHashCode;
//import lombok.NoArgsConstructor;
//
//import java.io.Serializable;
//import java.util.List;
//
//
//@Data
//@NoArgsConstructor
//@AllArgsConstructor
//@EqualsAndHashCode(callSuper = false)
//public class SpuDto extends BaseDTO  {
//    private Long id;
//    private String name;
////    private String title;
//    private Long cid1;
//    private Long cid2;
//    private Long cid3;
//    private Long brandId;
//    private Boolean saleable;
//    private String brandName;
//    private String categoryName;
//
//    private List<SkuDto> skuDtos;
//    private SpuDetailsDto spuDetailsDto;
//
//    public SpuDto(BaseEntity entity) {
//        super(entity);
//    }
//
//
//    public <T> T toEntity(Class<T> entityClass) {
//        return super.toEntity(entityClass);
//    }
//}


















package com.leyou.pojo.dto;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.leyou.common.dto.BaseDTO;
import com.leyou.common.entity.BaseEntity;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;

import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;

/** * @author HuYi
 */
@Data
@NoArgsConstructor
@EqualsAndHashCode(callSuper = false)
public class SpuDto extends BaseDTO {
    private Long id;
    private Long brandId;
    private Long cid1;// 1级类目
    private Long cid2;// 2级类目
    private Long cid3;// 3级类目
    private String name;// 名称
    private String title;// 标题
    private Boolean saleable;// 是否上架
    private String categoryName; // 商品分类名称拼接
    private String brandName;// 品牌名称
    /**
     * 商品详情
     */
    private SpuDetailsDto spuDetail;
    /**
     * spu下的sku的集合
     */
    private List<SkuDto> skus;
    /**
     * 方便同时获取3级分类
     * @return 3级分类的id集合
     */
    @JsonIgnore
    public List<Long> getCategoryIds(){
        return Arrays.asList(cid1, cid2, cid3);
    }

    public SpuDto(BaseEntity entity) {
        super(entity);
    }

    public static <T extends BaseEntity> List<SpuDto> convertEntityList(Collection<T> list){
        if (list == null) {
            return Collections.emptyList();
        }
        return list.stream().map(SpuDto::new).collect(Collectors.toList());
    }
}